/**
 * Copyright(C) 2012-2014 shenzhen gcn99 Co., Ltd. All Rights Reserved.<br/>
 * 版权所有(C)2012-2014 <br/>
 * 公司名称：金中国黄金珠宝商城<br/>
 * 公司地址：广东省深圳市罗湖区文锦北路2028号逸湖居大厦三楼金中国<br/>
 * 网址：http://www.230la.net/com/3088909391/<br/>
 * <p>标        题：</p>
 * <p>文  件  名：com.goldcn.file.controller.FileController.java</p>
 * <p>部        门：研发一部
 * <p>版        本： 1.0</p>
 * <p>Compiler: JDK1.6.0_21</p>
 * <p>创  建  者：kylin.woo</p>
 * <p>创建时间：2016/03/04</p>
 * <p>修  改  者：</p>
 * <p>修改时间：</p>
 */

package com.goldcn.file.controller;

import com.goldcn.file.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * 文件上传处理类
 */
@RestController
@RequestMapping(value = "/file")
public class FileController {

    @Autowired
    UploadService uploadService;

    @RequestMapping(method = RequestMethod.POST, value = "/uploadfile")
    public Object uploadfile(@RequestParam("file") MultipartFile file) {
        try {
            return uploadService.uploadFiles(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "{code:'success'}";
    }

    @RequestMapping(method = RequestMethod.GET, value = "/download/{fileName:.+}")
    public Object downLoad(@PathVariable String fileName,HttpServletResponse response) {
        try {
            response.setContentType("text/html; charset=utf-8");
            uploadService.downLoad(response,fileName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "{code:'success'}";
    }


}
